<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Today extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        $keywords = $this->request->param('keywords');
        $area_id = (int)$this->request->param('area_id');
        $where = [];
        if(!empty($keywords)) {
            $where['name'] = ['like', '%'.$keywords.'%'];
        }
        if($area_id) {
            $where['area_id'] = $area_id;
        }
        $list = Db::name('product')->where(['status' => 1])->where($where)->paginate(10);
        // if($list) {
        //     $request = Request::instance();
        //     foreach ($list as $k => $v) {
        //         $list[$k]['cover'] = $request->domain() . $v['cover'];
        //     }
        // }
        $page = $list->render();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->assign('area_id', $area_id);
        $this->assign('title', '今日特价');
        return $this->view->fetch();
    }

}
